package edu.tapestry.iddb.client.pages;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

public class Guess {
	@Persist
	private int target;

	@Property
	@Persist
	private int guess;

	Object initialize(int target) {
		this.guess = target;

		return this;
	}

	public int getTarget() {
		return target;
	}

	@Persist
	@Property
	private String message;

	String onActionFromLink(int guess) {
		if (guess == target)
			return "GameOver";

		if (guess < target)
			message = String.format("%d is too low. (%d)", guess, this.guess);
		else
			message = String.format("%d is too high. (%d)", guess, this.guess);

		return null;
	}
}
